import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;


public class Processor implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1328706903699167701L;
	private String id;
	private ArrayList<String> links = new ArrayList<String>();
	private List<ProcessInfo> history = new ArrayList<ProcessInfo>();

	public Processor(String id){
		this.setID(id);
	}

	private void setID(String id) {
		this.id = id;

	}

	public String getID() {
		return this.id;
	}

	public void addLink(String link){
		if (!this.links.contains(link))
			this.links.add(link);
	}

	public void removeLink(String link){
		this.links.remove(link);
	}
	
	public ArrayList<String> getLinks(){
		return this.links;
	}

	public List<ProcessInfo> getHistory() {
		return history;
	}

	public void setHistory(List<ProcessInfo> history) {
		this.history = history;
	}
	
	public void addToHistory(ProcessInfo processInfo) {
		history.add(processInfo);
	}
	
	public boolean searchHistory(ProcessInfo processInfo) {
		for (ProcessInfo process : history) {
			if(processInfo.getTime() == process.getTime() && processInfo.getBroadcast().getMessage().equals(process.getBroadcast().getMessage())
					&& processInfo.getId().equals(process.getId())) {
				return true;
			}
			
		}
		return false;
	}
	
	public List<ProcessInfo> getFromHistory(double tempo) {
		List<ProcessInfo> result = new ArrayList<ProcessInfo>();
		for (ProcessInfo processInfo : history) {
			if(processInfo.getTime() == tempo) {
				result.add(processInfo);
			}
		}
		return result;
	}
}
